﻿@{
    ViewData["Title"] = "完成项目";
}


 
        <div class="layui-fluid">
            <div class="layui-card">
                <div class="layui-form layui-card-header layuiadmin-card-header-auto search" lay-filter="app-content-list">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">项目名称</label>
                            <div class="layui-input-inline">
                                <input type="text" name="name" placeholder="请输入" autocomplete="off" class="layui-input">
                            </div>
                        </div>

                        <div class="layui-inline">
                            <button class="layui-btn layuiadmin-btn-list" id="searchBtn" lay-submit="" lay-filter="search">
                                <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>查询
                            </button>                            
                        </div>
                    </div>
                </div>

                <div class="layui-card-body">                    
                    <table id="LAY-app-content-list" lay-filter="LAY-app-content-list"></table>
                </div>
            </div>
        </div>

  


<script>


    //分模块加载js
    var $ = layui.$
        , view = layui.view
        , table = layui.table
        ,layer = layui.layer
        , form = layui.form
        , laydate = layui.laydate
        element = layui.element,
        upload = layui.upload;

 

    //监听搜索
    form.on('submit(search)', function (data) {
        var field = data.field;
        //执行重载
        table.reload('LAY-app-content-list', {
            where: field
        });
    });


    //加载table
    var tableObj = table.render({
        elem: '#LAY-app-content-list'
        , url: '/project/finishList'
        , page: true
        , height: 'full-110'
        , cols: [[
            { field: 'name', title: '项目名称', minWidth: 100, templet: '<div><a class="link" onclick="showDetail(\'{{ d.id}}\')">{{d.name}}</a></div>' }
            , { field: 'deviceType', title: '建设单位', width: 100, templet: '<div>{{ d.developUnit}}</div>' }
            , { field: 'buyUser', title: '使用单位', width: 120, templet: '<div>{{ d.useUnit}}</div>' }
            , { field: 'buyUser', title: '绑定合同', width: 120, templet: '<div>{{ getContract(d.contract)}}</div>' }
            , { field: 'amount', title: '投资金额', width: 120, templet: '<div>{{ d.amount}}</div>' }
            , { field: 'startDate', title: '开始时间', width: 150, templet: '<div>{{ d.startTime.substring(0,10)}}</div>' }
            , { field: 'cyr', title: '部门', width: 100, templet: '<div>{{ getDepart(d.depart) }}</div>' }
            , { field: 'startDate', title: '参与人', width: 150, templet: '<div>{{ d.participate }}</div>' }

        ]]
        , skin: 'line'
        , done: function () {
            $("td").on("mouseenter", function () {
                var cell = $(this).find(".layui-table-cell")[0];
                if (cell.offsetWidth < cell.scrollWidth) {
                    var that = this;
                    var text = $(this).text();
                    layer.tips(text, that, {
                        time: 2000
                    });
                }

            });
        }
    });  
     

    function getContract(c) {
        if (c == null) return "";
        return c.title;
    }

    //新增合同
    function add() {
        window.location.href = "/project/edit";
    }

    //完成项目
    function goFinish(id) {
        $.get("/project/goFinish?id="+id, function (str) {
            var index = layer.open({
                type: 1,
                title: '完成项目',
                area: "450px",
                content: str 
            });

            form.render("", 'finishForm');
            laydate.render({ elem: "#finishDate" });

            //监听提交
            form.on('submit(finish)', function (data) {
                var field = data.field; //获取提交的字段 
                //提交 Ajax 成功后，关闭当前弹层并重载表格
                $.post("/project/doFinish", field, function (d) {
                    layer.msg(d.msg);
                    if (d.code == 1) {
                        tableObj.reload();
                        layer.close(index);
                    }                    
                });

            });
        });
    }    

    function deleteItem(id) {
        layer.confirm("确定要删除吗？", function (index) {
            layer.close(index);
            $.post("/project/delete?id=" + id, function (d) {
                layer.msg(d.msg);
                if (d.code == 1) {
                    tableObj.reload();
                }
            });
        });
    }

    function showDetail(id) {
        layer.open({
            mask: 0,
            type: 2,
            content: '/project/Detail?id=' + id,
            area: ["1000px", "550px"]
        });
    }

    $(document).on('keydown', function (e) {  
        if (e.keyCode == 13) {
            $("#searchBtn").click();
        }
    })

    function getDepart(d) {
        if (d != null) {
            return d.name;
        }
        return "";
    }   
</script>

